package cn.ibizlab.odoo.core.odoo_base.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ibase_module_uninstall;
import cn.ibizlab.odoo.core.odoo_base.domain.Base_module_uninstall;
import cn.ibizlab.odoo.core.odoo_base.filter.Base_module_uninstallSearchContext;
import cn.ibizlab.odoo.core.odoo_base.service.IBase_module_uninstallService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[模块卸载] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Base_module_uninstallServiceImpl implements IBase_module_uninstallService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ibase_module_uninstallClientService base_module_uninstallClientService;

    @Override
    public boolean update(Base_module_uninstall base_module_uninstall) {
        boolean bOk = false ;
        Ibase_module_uninstall clientModel = this.convert2Model(base_module_uninstall,null);
        base_module_uninstallClientService.update(clientModel) ;
        this.convert2Domain(clientModel,base_module_uninstall) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Base_module_uninstall get(Integer id) {
        Ibase_module_uninstall clientModel = base_module_uninstallClientService.createModel();
        clientModel.setId(id);
        base_module_uninstallClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Base_module_uninstall get(Base_module_uninstall base_module_uninstall) {
        Base_module_uninstall retbase_module_uninstall = this.get(base_module_uninstall.getId()) ;
    	BeanCopier copier=BeanCopier.create(retbase_module_uninstall.getClass(), base_module_uninstall.getClass(), false);
        copier.copy(retbase_module_uninstall, base_module_uninstall, null);
        return base_module_uninstall ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //base_module_uninstallClientService.removeBatch(base_module_uninstalls) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ibase_module_uninstall clientModel = base_module_uninstallClientService.createModel();
        clientModel.setId(id);
        base_module_uninstallClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Base_module_uninstall> base_module_uninstalls, int batchSize) {

        //base_module_uninstallClientService.updateBatch(base_module_uninstalls,batchSize) ;

    }

    @Override
    public void createBatch(List<Base_module_uninstall> base_module_uninstalls, int batchSize) {

                        //base_module_uninstallClientService.createBatch(base_module_uninstalls,batchSize) ;

    }

    @Override
    public boolean create(Base_module_uninstall base_module_uninstall) {
        boolean bOk = false ;
        Ibase_module_uninstall clientModel = this.convert2Model(base_module_uninstall,null);
        base_module_uninstallClientService.create(clientModel) ;
        this.convert2Domain(clientModel,base_module_uninstall);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Base_module_uninstall> searchDefault(Base_module_uninstallSearchContext context) {
        List<Base_module_uninstall> list = new ArrayList<Base_module_uninstall>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_module_uninstall> clientModelList = base_module_uninstallClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_module_uninstall clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_module_uninstall>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_module_uninstall> selectByOdoo_create(Integer id){
        Base_module_uninstallSearchContext context = new Base_module_uninstallSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_module_uninstall> list = new ArrayList<Base_module_uninstall>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_module_uninstall> clientModelList = base_module_uninstallClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_module_uninstall clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_module_uninstall>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Base_module_uninstall> selectByOdoo_write(Integer id){
        Base_module_uninstallSearchContext context = new Base_module_uninstallSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Base_module_uninstall> list = new ArrayList<Base_module_uninstall>();
        Page<cn.ibizlab.odoo.core.client.model.Ibase_module_uninstall> clientModelList = base_module_uninstallClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ibase_module_uninstall clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Base_module_uninstall>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ibase_module_uninstall convert2Model(Base_module_uninstall domain , Ibase_module_uninstall model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = base_module_uninstallClientService.createModel() ;
        }

         if(domain.getModule_idsDirtyFlag())
            model.setModule_ids(domain.getModule_ids());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getModel_idsDirtyFlag())
            model.setModel_ids(domain.getModel_ids());
         if(domain.getShow_allDirtyFlag())
            model.setShow_all(domain.getShow_all());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getModule_idDirtyFlag())
            model.setModule_id(domain.getModule_id());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Base_module_uninstall convert2Domain( Ibase_module_uninstall model ,Base_module_uninstall domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Base_module_uninstall();
        }

        if(model.getModule_idsDirtyFlag())
            domain.setModule_ids(model.getModule_ids());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getModel_idsDirtyFlag())
            domain.setModel_ids(model.getModel_ids());
        if(model.getShow_allDirtyFlag())
            domain.setShow_all(model.getShow_all());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getModule_idDirtyFlag())
            domain.setModule_id(model.getModule_id());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
